package quick.start.core.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

public abstract class DefaultPagingListAdapter<T> extends BaseAdapter {

	private PagingResult<T> pagingResult;
	private LayoutInflater inflater;
	protected Context context;
	
	public DefaultPagingListAdapter(Context context){
		this.context = context;
	}
	
	public void setData(PagingResult<T> data){
		this.pagingResult = data;
	}
	
	public void appendData(PagingResult<T> data){
		if(null == pagingResult)
			throw new IllegalArgumentException("paging Result not set, please call setData first!");
		
		this.pagingResult.getItems().addAll(data.getItems());
		if(data.getTotalCount() != 0){
			this.pagingResult.setTotalCount(data.getTotalCount());
		}
	}
	
	public Context getContext(){
		return this.context;
	}
	
    @Override
    public int getCount() {
        return null == pagingResult ? 0 : pagingResult.getTotalCount();
    }

    @Override
    public Object getItem(int position) {
        return pagingResult.getItems().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
